package com.huaxin.hxcloud.dialog;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.huaxin.common.Constants;
import com.huaxin.common.utils.ToastUtil;
import com.huaxin.hxcloud.R;
import com.huaxindata.common.base.HxBaseDialogFragment;

import butterknife.BindView;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * @author songxf
 * @date 2018/6/15
 * @Desc SPT修改模拟量dialogFragment
 * Copyright HUAXIN DATA. All rights reserved.
 */
public class HxSPTSimulateTargerDialog extends HxBaseDialogFragment {
    @BindView(R.id.title_id)
    TextView mTitleId;
    @BindView(R.id.des_tv)
    TextView mDesTv;
    @BindView(R.id.input_paswd_et)
    EditText mInputPaswdEt;
    @BindView(R.id.line_view)
    View     mLineView;
    @BindView(R.id.cancel_tv)
    TextView mCancelTv;
    @BindView(R.id.ensure_tv)
    TextView mEnsureTv;
    Unbinder unbinder;

    public void setOnItemSimulateClickListener(OnItemSimulateClickListener onItemSimulateClickListener) {
        mOnItemSimulateClickListener = onItemSimulateClickListener;
    }

    private OnItemSimulateClickListener mOnItemSimulateClickListener;

    public interface OnItemSimulateClickListener {
        void onItemSimulateClick(String value);
    }

    public static HxSPTSimulateTargerDialog newInstance() {

        Bundle args = new Bundle();

        HxSPTSimulateTargerDialog fragment = new HxSPTSimulateTargerDialog();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int setRootViewId() {
        return R.layout.dialog_spt_simulate_targer;
    }

    @Override
    public void initData() {
        Bundle bundle = getArguments();
        String targetName = bundle.getString(Constants.TARGET_NAME);
        if (!TextUtils.isEmpty(targetName)) {
            mDesTv.setText(targetName);
        }
    }

    @Override
    public int showPosition() {
        return Gravity.CENTER;
    }


    @OnClick({R.id.cancel_tv, R.id.ensure_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.cancel_tv:
                if (this.getShowsDialog()) {
                    this.dismiss();
                }
                break;
            case R.id.ensure_tv:
                String vavleStr = mInputPaswdEt.getText().toString().trim();
                if (TextUtils.isEmpty(vavleStr)) {
                    ToastUtil.showToast("输入内容不能为空");
                    return;
                }
                mOnItemSimulateClickListener.onItemSimulateClick(vavleStr);
                break;
        }
    }
}
